package com.nineshadow.games.interfaces;

import cn.stylefeng.guns.modular.system.model.GameUser;
import com.nineshadow.games.netty.message.MessageSend;
import com.nineshadow.games.entity.PollHandler;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.LoggerFactory;

import java.util.Objects;

/**
 * <p>
 * 游戏用户
 * </p>
 *
 * @author ting liu
 * @since 2019/5/17 10:45
 */
public interface IGameUser {

    GameUser getUserInfo();

    void setUserInfo(GameUser userInfo);

    int getUserId();

    String getNickName();

    ChannelHandlerContext getCtx();

    void setCtx(ChannelHandlerContext ctx);

    default boolean equals(IGameUser user) {
        return !Objects.isNull(user) && getUserId() == user.getUserId();
    }

    default void sendMsg(Object msg, String url) {
        try {
            ChannelHandlerContext ctx = getCtx();
            if (!Objects.isNull(ctx)) {
                MessageSend.send(ctx, url, msg, false);
            }
        } catch (Exception e) {
            LoggerFactory.getLogger(getClass()).error(e.getMessage(), e);
        }
    }

    void offline(ChannelHandlerContext ctx);

    void removeUserInfo();

    void setLastRoomId(String roomId);

    String getLastRoomId();

    PollHandler getPollHandler();

    void setPollHandler(PollHandler pollHandler);
}
